#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e5 + 10;
const int MAXM = 1e5 + 10;
const int MAXT = 10;

int T;
namespace Solve
{
  int n, m, L, V, d[MAXN], v[MAXN], a[MAXN], p[MAXM];
  int closePre, closePost, cnt;
  void aPlus(int d, int v, int a)
  {
    if (v > V)
    {
      int l = 1, r = m, idx;
      while (l <= r)
      {
        int mid = (l + r) >> 1;
        if (p[mid] >= d)
        {
          idx = mid;
          r = mid - 1;
        }
        else
          l = mid + 1;
      }
      cnt++;
      closePost = min(closePost, m - idx + 1);
    }
    else
    {
      d += ceil(1.0 * (V * V - v * v) / 2 / a);
      if (d >= L)
        return;
      int l = 1, r = m, idx;
      while (l <= r)
      {
        int mid = (l + r) >> 1;
        if (p[mid] >= d)
        {
          idx = mid;
          r = mid - 1;
        }
        else
          l = mid + 1;
      }
      cnt++;
      closePost = min(closePost, m - idx + 1);
    }
  }
  void aZero(int d, int v)
  {
    if (v > V && d < L)
    {
      int l = 1, r = m, idx;
      while (l <= r)
      {
        int mid = (l + r) >> 1;
        if (p[mid] > d)
          r = mid - 1;
        else
        {
          idx = mid;
          l = mid + 1;
        }
      }
      cnt++, closePost = min(closePost, m - idx);
    }
  }
  void aMinus(int d, int v, int a)
  {
    if (v <= V)
      return;
    int stoppos = min(L, (int)(d + ceil(1.0 * (-v * v) / 2 / a)));
    d += ceil(1.0 * (V * V - v * v) / 2 / a);
    if (d > stoppos)
      return;
    cnt++;
    int idx = lower_bound(p + 1, p + 1 + m, d) - p;
    int endpos = lower_bound(p + 1, p + 1 + m, stoppos) - p - 1;
    if (endpos >= m - closePost)
      closePost = m - idx;
  }
  void solve()
  {
    scanf("%d%d%d%d", &n, &m, &L, &V);
    for (int i = 1; i <= n; i++)
      scanf("%d%d%d", d + i, v + i, a + i);
    for (int i = 1; i <= m; i++)
      scanf("%d", p + i);
    closePre = closePost = m - 1;
    cnt = 0;
    for (int i = 1; i <= n; i++)
      if (!a[i])
        aZero(d[i], v[i]);
      else
        aPlus(d[i], v[i], a[i]);
    for (int i = 1; i <= n; i++)
      if (a[i] < 0)
        aMinus(d[i], v[i], a[i]);
    printf("%d %d\n", cnt, min(m, closePost + closePre));
  }
}
using namespace Solve;

int main()
{
  freopen("detect.in", "r", stdin);
  freopen("detect.out", "w", stdout);
  scanf("%d", &T);
  while (T--)
  {
    scanf("%d%d%d%d", &n, &m, &L, &V);
    for (int i = 1; i <= n; i++)
      scanf("%d%d%d", d + i, v + i, a + i);
    for (int i = 1; i <= m; i++)
      scanf("%d", p + i);
    cnt = 0;
    for (int i = 1; i <= n; i++)
    {
      if (v[i] > V && d[i] <= p[m])
        cnt++;
    }
    printf("%d %d\n", cnt, m - (int)(bool)(cnt));
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}